Skip to content

PKCS#11 Ed25519 tests#618

Merged
jforissier merged 1 commit intoOP-TEE:masterfrom
varder:pkcs11_ed25519
Oct 25, 2022
Merged

PKCS#11 Ed25519 tests#618
jforissier merged 1 commit intoOP-TEE:masterfrom
varder:pkcs11_ed25519

Conversation

@varder
Copy link
Copy Markdown

@varder varder commented Sep 29, 2022

Adds tests to import, sign and verify Ed25519, Ed25519ctx and Ed25519ph.

The pull request comes with the following pull requests:
OP-TEE/optee_os#5559
OP-TEE/optee_os#5574

Copy link
Copy Markdown
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pkcs11 part looks good to me (aside the few minor comments)

Comment thread host/xtest/pkcs11_1000.c Outdated
.public_len = ARRAY_SIZE(_vect ##_public), \
.flag = _flag, \
.context = _vect ## _context, \
.context_len = ARRAY_SIZE(_vect ##_context), \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread host/xtest/pkcs11_1000.c Outdated
size_t private_len;
const uint8_t *public;
size_t public_len;
const bool flag;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename ph_flag as this is the pre-hash flag?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

Comment thread host/xtest/pkcs11_1000.c Outdated
goto err;

rv = C_Sign(session, (CK_BYTE_PTR)test->message, test->message_len,
(CK_BYTE_PTR)sign, &sign_len);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation (and at line 7972)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread host/xtest/pkcs11_1000.c Outdated

CK_ATTRIBUTE public_key_template[] = {
{ CKA_CLASS, &(CK_OBJECT_CLASS){ CKO_PUBLIC_KEY }, sizeof(CK_OBJECT_CLASS) },
{ CKA_KEY_TYPE, &(CK_KEY_TYPE){CKK_EC_EDWARDS}, sizeof(CK_KEY_TYPE) },
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: space char around CKK_EC_EDWARDS: { CKK_EC_EDWARDS }

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread host/xtest/pkcs11_1000.c Outdated

static struct eddsa_test eddsa_sign_tests[] = {
CKTEST_EDDSA_TEST(ed25519_params, ed25519_rfc_8032_7_1, 0),
CKTEST_EDDSA_TEST(ed25519_params, ed25519_rfc_8032_7_1, 1),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like an extra tests, testing vector 7.1 with pre-hash enabled. The EdDSA RFC mentions this test setup?
Same question at line 7850.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, removed

@varder
Copy link
Copy Markdown
Author

varder commented Oct 17, 2022

Hi @etienne-lms,
Could you please have a look at the updates?
Thanks

Copy link
Copy Markdown
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @varder for the late feedback. Error path issues to address.

Comment thread host/xtest/pkcs11_1000.c Outdated
ADBG_EXPECT_CK_OK(c, C_DestroyObject(session, public_key));
}

err:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are several things to clean on error case. I suggest:

 		ADBG_EXPECT_CK_OK(c, C_DestroyObject(session, private_key));
 		ADBG_EXPECT_CK_OK(c, C_DestroyObject(session, public_key));
 	}
 
+	ADBG_EXPECT_CK_OK(c, C_CloseSession(session));
+	ADBG_EXPECT_CK_OK(c, close_lib());
+	return;
+
-err:
+err_destroy_keys
+	ADBG_EXPECT_CK_OK(c, C_DestroyObject(session, private_key));
+	ADBG_EXPECT_CK_OK(c, C_DestroyObject(session, public_key));
+err_close_sess:
+	C_CloseSession(session);
+err_close_lib:
+	close_lib();
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done,
Thank for providing the solution

Comment thread host/xtest/pkcs11_1000.c Outdated
ARRAY_SIZE(private_key_template),
&private_key);
if (!ADBG_EXPECT_CK_OK(c, rv))
goto err;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should destroy the created persistent (token) object public_key above.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread host/xtest/pkcs11_1000.c Outdated

rv = C_SignInit(session, &sign_mechanism, private_key);
if (!ADBG_EXPECT_CK_OK(c, rv))
goto err;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failing here needs to attempt to destroy created persistent object(s).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread host/xtest/pkcs11_1000.c Outdated
CKF_SERIAL_SESSION | CKF_RW_SESSION,
NULL, NULL, &session);
if (!ADBG_EXPECT_CK_OK(c, rv))
goto err;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goto err_close_lib;
and only call close_lib()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@varder
Copy link
Copy Markdown
Author

varder commented Oct 20, 2022

Hi @etienne-lms
Can I squash the commit?

Copy link
Copy Markdown
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I squash the commit?

Ok.
Acked-by: Etienne Carriere <etienne.carriere@linaro.org>

Adds tests to import, sign and verify ED25519,
ED25519ctx and ED25519ph.

The PKCS11 Specification:
https://docs.oasis-open.org/pkcs11/pkcs11-spec/v3.1/cs01/
pkcs11-spec-v3.1-cs01.pdf

Signed-off-by: Valerii Chubar <valerii_chubar@epam.com>
Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
@jforissier jforissier merged commit e4f3cd1 into OP-TEE:master Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants